<?php
/*===================================
 //==全局函数
===================================*/

/**
 * 模板方法
 * @param string $module 模块
 * @param string $template 模板
 * @param string $style 样式
 */
function template($module = 'content', $tpl = 'index', $style = 'default') {
	$tplfile = APP_TPL_ROOT."$style/$module/$tpl.html";
	$cpledfile = TPL_CACHE_ROOT."$style/$module/$tpl.php";
	if(file_exists($tplfile)){
		if(!file_exists($cpledfile) || (@filemtime($tplfile) > @filemtime($cpledfile))) {
			$tplcpl = new templatecpl();
			$tplcpl->template_compile($tplfile, $cpledfile, $style);
		}
	}else {
		if($style=='default') exit('err:tpl missing');
		$tplfile = APP_TPL_ROOT."default/$module/$tpl.html";
		if(!file_exists($tplfile)) exit('err:tpl missing');
		$cpledfile = TPL_CACHE_ROOT."default/$module/$tpl.php";
		if(!file_exists($cpledfile) || (@filemtime($tplfile) > @filemtime($cpledfile))){
			$tplcpl = new templatecpl();
			$tplcpl->template_compile($tplfile, $cpledfile, $style);
		}
	}
	return $cpledfile;
}
/**
 * 根据模板+数据直接输出html
 * @param 模块名 $module
 * @param 模板名 $tpl
 * @param array $data
 * @param bool $return 
 */
function hwidget($module,$tpl,$data,$return=false){
	if($return){
		ob_start();
		ob_implicit_flush(false);
	}
	if($module&&$tpl){
		if($data){
			extract($data,EXTR_OVERWRITE);
		}
		include template($module,$tpl);
		if($return){
			return ob_get_clean();
		}
	}
}
/**
 * 管理模板
 * @param string $module
 * @param  $tplname
 */
function admtpl($module,$tplname){
	return HAPP_MODULES_ROOT."admin/templates/${module}/$tplname.php";
}


/**
 * 显示信息
 * @param string $msg 消息
 * @param string $title 内容
 * @param string $returl 返回URL
 */

/**
 * 显示信息,并退出PHP处理过程
 * @param string $msg
 * @param string $url_forward goback/close/blank 及URL
 * @param unknown_type $ms
 * @param unknown_type $dialog
 * @param unknown_type $returnjs
 */
function hmsg($msg='未知异常', $url_forward = 'goback', $ms = 1250, $dialog = '', $returnjs = ''){
	if(IN_HADMIN===1){
		include admtpl('admin','msg');
	}else{
		include template('common','msg');
	}
	exit;
}

/**
 * 输出CSS,加上全局版本号
 * @param string $name CSS文件名
 * @param string $module 默认global
 * @param bool $echo true输出内容不返回，false返回字符串
 * @return string
 */
function hcss($name, $module='global', $echo=false,$urlroot=HSTATIC_URL_ROOT){
	if($echo){
		echo '<link rel="stylesheet" type="text/css" href="',$urlroot,$module,'/css/',$name,'.css?v=',HSTATIC_VER,'" media="all" />';
	}else{
		return '<link rel="stylesheet" type="text/css" href="'.$urlroot.$module.'/css/'.$name.'.css?v='.HSTATIC_VER.'" media="all" />';
	}
}

/**
 * 输出JS,加上全局版本号
 * @param string $name JS文件名
 * @param string $module 默认global
 * @param bool $echo  true输出内容不返回，false返回字符串
 * @return string
 */
function hjs($name, $module='global', $echo=false,$urlroot=HSTATIC_URL_ROOT){
	if($echo){
		echo '<script type="text/javascript" src="',$urlroot,$module,'/js/',$name,'.js?v=',HSTATIC_VER,'"></script>';
	}else{
		return '<script type="text/javascript" src="'.$urlroot.$module.'/js/'.$name.'.js?v='.HSTATIC_VER.'"></script>';
	}
}

/**
 * 输出图片路径,注意：只是路径，不加上<IMG,也不加上全局版本号
 * @param string $name JS文件名
 * @param string $module 默认global
 * @param bool $echo  true输出内容不返回，false返回字符串
 * @return string
 */
function himg($name, $module='global', $echo=false,$urlroot=HSTATIC_URL_ROOT){
	if($echo){
		echo $urlroot,$module,'/img/',$name;
	}else{
		return $urlroot.$module.'/img/'.$name;
	}
}

/**
 * 获取碎片文本，通过POS
 * @param string $pos
 */
function hblock($pos){
	return block::I()->getdata_bypos($pos);
}

/**
 * 验证码,生成验证码IMG
 * @param string $img_id 生成的<img id=$img_id
 * @param int $code_len
 * @param int $font_size
 * @param int $width
 * @param int $height
 * @param string $font_color
 * @param string $background
 * @return string
 */
function hverifycode($img_id,$code_len = 4, $font_size = 20, $width = 130, $height = 50, $font_color = '', $background = ''){
	return "<img id='$img_id' onclick='this.src=this.src+\"&\"+Math.random()' src='".hurl('api','index','verifycode')."&code_len=$code_len&font_size=$font_size&width=$width&height=$height&font_color=".urlencode($font_color)."&background=".urlencode($background)."'>";
}

/**
 * 分页函数
 *
 * @param int $num 信息总数
 * @param int $curr_page 当前分页
 * @param int $pagesize 每页显示数
 * @param string $urlrule URL规则
 * @param array $param URL的其它参数
 * @param int 页码个数
 * @return 分页HTML
 */
function pages($num, $curr_page, $pagesize = HDEF_PAGE_SIZE, $urlrule, $param=array(), $setpages = 10) {
	//$urlrule = fx_utl::combine_url_param($urlrule,'page={page}');
	$multipage = '';
	if($num > $pagesize) {
		$page = $setpages+1;
		$offset = ceil($setpages/2-1);
		$pages = ceil($num / $pagesize);
		if (defined('IN_HADMIN') && !defined('PAGES')) define('PAGES', $pages);
		$from = $curr_page - $offset;
		$to = $curr_page + $offset;
		$more = 0;
		if($page >= $pages) {
			$from = 2;
			$to = $pages-1;
		} else {
			if($from <= 1) {
				$to = $page-1;
				$from = 2;
			}  elseif($to >= $pages) {
				$from = $pages-($page-2);
				$to = $pages-1;
			}
			$more = 1;
		}
		$multipage .= '<a class="a1">共'.$num.'条</a>';
		if($curr_page>0) {
			$multipage .= ' <a href="'.pageurl($urlrule, $curr_page-1, $param).'" class="a1">上一页</a>';
			if($curr_page==1) {
				$multipage .= ' <span>1</span>';
			} elseif($curr_page>6 && $more) {
				$multipage .= ' <a href="'.pageurl($urlrule, 1, $param).'">1</a>..';
			} else {
				$multipage .= ' <a href="'.pageurl($urlrule, 1, $param).'">1</a>';
			}
		}
		for($i = $from; $i <= $to; $i++) {
			if($i != $curr_page) {
				$multipage .= ' <a href="'.pageurl($urlrule, $i, $param).'">'.$i.'</a>';
			} else {
				$multipage .= ' <span>'.$i.'</span>';
			}
		}
		if($curr_page<$pages) {
			if($curr_page<$pages-5 && $more) {
				$multipage .= ' ..<a href="'.pageurl($urlrule, $pages, $param).'">'.$pages.'</a> <a href="'.pageurl($urlrule, $curr_page+1, $param).'" class="a1">下一页</a>';
			} else {
				$multipage .= ' <a href="'.pageurl($urlrule, $pages, $param).'">'.$pages.'</a> <a href="'.pageurl($urlrule, $curr_page+1, $param).'" class="a1">下一页</a>';
			}
		} elseif($curr_page==$pages) {
			$multipage .= ' <span>'.$pages.'</span> <a href="'.pageurl($urlrule, $curr_page, $param).'" class="a1">下一页</a>';
		} else {
			$multipage .= ' <a href="'.pageurl($urlrule, $pages, $param).'">'.$pages.'</a> <a href="'.pageurl($urlrule, $curr_page+1, $param).'" class="a1">下一页</a>';
		}
		if(true){
			$jsurlrule=str_replace('{page}', '_PAGE_', $urlrule);
			$hrpageinputid=fx_utl::create_guid();
			$multipage.='<span class="q-pages-sp"><em class="q-pages-em">跳到</em><input class="q-pages-insert" type="text" id="'.$hrpageinputid.'" url="'.$jsurlrule.'" maxpage="'.$pages.'"/><em class="q-pages-em">页</em><a class="q-pages-btn" href="javascript:HR.biz.hpageskip(\''.$hrpageinputid.'\');" />确定</a></span>';
			$multipage.='<script type="text/javascript">HR.biz.hpageskip_bindEnter("'.$hrpageinputid.'");</script>';
		}
	}
	return $multipage;
}
/**
 * 分页函数
 *
 * @param int $num 信息总数
 * @param int $curr_page 当前分页
 * @param int $pagesize 每页显示数
 * @param string $urlrule URL规则
 * @param array $param URL的其它参数
 * @param int 页码个数
 * @return 分页HTML
 */
function hpages($num, $curr_page, $pagesize = HDEF_PAGE_SIZE, $urlrule,$param=array(), $setpages = 8,$showtotal=true,$showpage=true,$showskip=true) {
	//$urlrule = fx_utl::combine_url_param($urlrule,'page={page}');
	$multipage = '';
	if($num > $pagesize) {
		$page = $setpages+1;
		$offset = ceil($setpages/2-1);
		$pages = ceil($num / $pagesize);
		if (defined('IN_HADMIN') && !defined('PAGES')) define('PAGES', $pages);
		$from = $curr_page - $offset;
		$to = $curr_page + $offset;
		$more = 0;
		if($page >= $pages) {
			$from = 2;
			$to = $pages-1;
		} else {
			if($from <= 1) {
				$to = $page-1;
				$from = 2;
			}  elseif($to >= $pages) {
				$from = $pages-($page-2);
				$to = $pages-1;
			}
			$more = 1;
		}
		if($showtotal)
		{
			$multipage .= '<a href="javascript:;" class="totalpage">共'.$num.'条</a>';
		}
		if($curr_page>0) {
			if($showpage){
				if($curr_page>1){
					$multipage .= '<a href="'.hpageurl($urlrule, $curr_page-1, $param).'" class="prepage">上一页</a>';
				}
			}
			if($curr_page==1) {
				$multipage .= '<span class="cur">1</span>';
			} elseif($curr_page>6 && $more) {
				$multipage .= '<a href="'.hpageurl($urlrule, 1, $param).'">1</a>..';
			} else {
				$multipage .= '<a href="'.hpageurl($urlrule, 1, $param).'">1</a>';
			}
		}
		for($i = $from; $i <= $to; $i++) {
			if($i != $curr_page) {
				$multipage .= '<a href="'.hpageurl($urlrule, $i, $param).'">'.$i.'</a>';
			} else {
				$multipage .= '<span  class="cur">'.$i.'</span>';
			}
		}
		if($curr_page<$pages) {
			if($curr_page<$pages-5 && $more) {
				$multipage .= '..<a href="'.hpageurl($urlrule, $pages, $param).'">'.$pages.'</a>';
			} else {
				$multipage .= '<a href="'.hpageurl($urlrule, $pages, $param).'">'.$pages.'</a>';
			}			
			if($showpage){
				$multipage.='<a href="'.hpageurl($urlrule, $curr_page+1, $param).'"  class="prepage">下一页</a>';
			}
		} elseif($curr_page==$pages) {
			$multipage .= '<span  class="cur">'.$pages.'</span>';
		} else {
			$multipage .= '<a href="'.hpageurl($urlrule, $pages, $param).'">'.$pages.'</a>';
		}
		if($showskip){
			$hrpageinputid=fx_utl::create_guid();
			$multipage.='<span class="q-pages-sp"><em class="q-pages-em">跳到</em><input class="q-pages-insert" type="text" id="'.$hrpageinputid.'" url="'.$urlrule.'" maxpage="'.$pages.'"/><em class="q-pages-em">页</em><a class="q-pages-btn" href="javascript:HR.biz.hpageskip(\''.$hrpageinputid.'\');" />确定</a></span>';
			$multipage.='<script type="text/javascript">HR.biz.hpageskip_bindEnter("'.$hrpageinputid.'");</script>';
		}
	}
	return $multipage;
}
/**
 * 返回跳转地址
 * @param string $url 
 * @param int $pageindex
 * @param array $array
 * @return mixed
 */
function hpageurl($url,$pageindex,$array=array())
{	
	return str_replace('_PAGE_', $pageindex, $url);
}
/**
 * 返回跳转地址
 * @param string $url
 * @param int $pageindex
 * @param array $array
 * @return mixed
 */
function pageurl($url,$pageindex,$array=array()){
	//$array 暂时没有用
	return str_replace('{page}', $pageindex, $url);
}

/**
 * 编码后的文本转为HTML标签
 * @param string $text
 */
function HD($text){
	return htmlspecialchars_decode ($text);
}

/**
 * 编码文本为HTML，并ECHO
 * @param string $text
 */
function HE($text){
	echo htmlspecialchars($text);
}

/**
 * 判断客户端是否IE浏览器
 * @return boolean
 */
function his_ie() {
	$useragent = strtolower($_SERVER['HTTP_USER_AGENT']);
	if((strpos($useragent, 'opera') !== false) || (strpos($useragent, 'konqueror') !== false)) return false;
	if(strpos($useragent, 'msie ') !== false) return true;
	return false;
}

/**
 * 获取头像图片
 * @param int $uid
 * @param string $size  small,middle,small
 * @param int $ver  头像版本号
 * @return string
 */
function havatarurl($uid, $size = 'middle',$ver=0,$real=true)
{
	$sysavatar = $ver & 0x0000FFFF;
	$ver = $ver >> 16;
	if(!$real)
	{	
		$uid = sprintf("%09d", $uid);
		$dir1 = substr($uid, 0, 3);
		$dir2 = substr($uid, 3, 2);
		$dir3 = substr($uid, 5, 2);
		$avatar=$dir1.'/'.$dir2.'/'.$dir3.'/'.substr($uid, -2).'_avatar_'.$size.'.jpg';
		return HSHARE_FILE_AVATAR_URL_ROOT.$avatar."?v=".$ver;
	}
	if($sysavatar){
		return HSHARE_FILE_AVATAR_URL_ROOT.'sys/'.$sysavatar.'_avatar_'.$size.'.png';	
	}	
	$size = in_array($size, array('big', 'middle', 'small')) ? $size : 'middle';
	$uid = abs(intval($uid));
	$sysavatar=$uid/2%9;
	static $avatarcache;
	$key=$uid.'-'.$size.'-'.$ver;
	if(!$avatarcache[$key])
	{
		$uid = sprintf("%09d", $uid);
		$dir1 = substr($uid, 0, 3);
		$dir2 = substr($uid, 3, 2);
		$dir3 = substr($uid, 5, 2);
		$avatar=$dir1.'/'.$dir2.'/'.$dir3.'/'.substr($uid, -2).'_avatar_'.$size.'.jpg';
		if(!file_exists(HSHARE_FILE_AVATAR_ROOT.$avatar))
		{			
			$sysavatar=max($sysavatar,1);
			$file=HSHARE_FILE_AVATAR_URL_ROOT.'sys/'.$sysavatar.'_avatar_'.$size.'.png';
		}
		else
		{
				$file = HSHARE_FILE_AVATAR_URL_ROOT.$avatar."?v=".$ver;
		}
		$avatarcache[$key]=$file;
	}
	return $avatarcache[$key] ;
}

/**
 * 显示时间处理转化为 多小时前，多少分钟，几天前形式
 * @param date $timestamp
 * @param boole $isShowDate
 * @param int $maxdays 显示最大天数时间戳（默认3天， 3*86400=259200） 
 * @return string
 */
function hdate($timestamp,$isShowDate=true,$span=false,$maxdays=259200){
	$limit = time() - $timestamp;
	if($span){
		$span1='<span class="gray9">';
		$span2='</span>';
	}
	if($limit < 60)
	{
		return $limit . $span1.'秒钟前'.$span2;
	}
	if($limit >= 60 && $limit < 3600)
	{
		return floor($limit/60) . $span1.'分钟前'.$span2;
	}
	if($limit >= 3600 && $limit < 86400)
	{
		return floor($limit/3600) .$span1. '小时前'.$span2;
	}
	if($limit >= 86400 && $limit<$maxdays)
	{
		return floor($limit/86400) .$span1. '天前'.$span2;
	}
	
	if($limit >= 259200 && $isShowDate)
	{
		return date('Y-m-d H:i:s', $timestamp);
	}else{
		return date('Y.m.d', $timestamp);
	}
}
/**
 * 显示时间处理转化为 多小时前，多少分钟，几天前形式
 * @param int $timestamp
 * @param string $format
 * @param int $timeoffset
 * @param unknown_type $uformat
 * @return string
 */
function hdgmdate($timestamp) {
	
	if($timestamp>strtotime(date('y-m-d',time())))
	{
		return date('H:i',$timestamp);
	}
	else
	{
		return date('Y-m-d H:i',$timestamp);
	}
	
	/* static $dformat, $tformat, $dtformat, $offset, $lang;
	if($dformat === null) {
		$dformat = "Y-n-j";
		$tformat = "H:i";
		$dtformat = $dformat.' '.$tformat;
		$offset = "8";
		$lang['before'] = "前";
		$lang['day'] = "天";
		$lang['yday'] = "昨天";
		$lang['byday'] = "前天";
		$lang['hour'] = "小时";
		$lang['half'] = "半";
		$lang['min'] = "分钟";
		$lang['sec'] = "秒";
		$lang['now'] = "刚刚";
	}
	$timeoffset = $timeoffset == 9999 ? $offset : $timeoffset;
	$timestamp += $timeoffset * 3600;
	$format = empty($format) || $format == 'dt' ? $dtformat : ($format == 'd' ? $dformat : ($format == 't' ? $tformat : $format));
	if($format == 'u') {
		$todaytimestamp = TIMESTAMP - (TIMESTAMP + $timeoffset * 3600) % 86400 + $timeoffset * 3600;
		$s = gmdate(!$uformat ? str_replace(":i", ":i:s", $dtformat) : $uformat, $timestamp);
		$time = TIMESTAMP + $timeoffset * 3600 - $timestamp;
		if($timestamp >= $todaytimestamp) {
			if($time > 3600) {
				return '<span title="'.$s.'">'.intval($time / 3600).'&nbsp;'.$lang['hour'].$lang['before'].'</span>';
			} elseif($time > 1800) {
				return '<span title="'.$s.'">'.$lang['half'].$lang['hour'].$lang['before'].'</span>';
			} elseif($time > 60) {
				return '<span title="'.$s.'">'.intval($time / 60).'&nbsp;'.$lang['min'].$lang['before'].'</span>';
			} elseif($time > 0) {
				return '<span title="'.$s.'">'.$time.'&nbsp;'.$lang['sec'].$lang['before'].'</span>';
			} elseif($time == 0) {
				return '<span title="'.$s.'">'.$lang['now'].'</span>';
			} else {
				return $s;
			}
		} elseif(($days = intval(($todaytimestamp - $timestamp) / 86400)) >= 0 && $days < 7) {
			if($days == 0) {
				return '<span title="'.$s.'">'.$lang['yday'].'&nbsp;'.gmdate($tformat, $timestamp).'</span>';
			} elseif($days == 1) {
				return '<span title="'.$s.'">'.$lang['byday'].'&nbsp;'.gmdate($tformat, $timestamp).'</span>';
			} else {
				return '<span title="'.$s.'">'.($days + 1).'&nbsp;'.$lang['day'].$lang['before'].'</span>';
			}
		} else {
			return $s;
		}
	} else {
		return gmdate($format, $timestamp);
	} */
}
/**
 * 月份下拉选择框
 * @param string $m
 * @param string $c
 * @param string $a
 * @param int $firstdate 开始时间
 * @param boo $isall 是否显示全部
 * @param int $default 默认选中的月份
 * @param string $parentid 父类容器对象的ID或CLASS
 * @return string $html
 */
function hdatePickup($m,$c,$a,$firstdate,$param,$isall,$default,$parentid){
	$nowdate = time();
	
	$firstyear = idate('Y', $firstdate);
	$firstmonth = idate('m', $firstdate);
	
	$nowyear = idate('Y', $nowdate);
	$nowmonth = idate('m', $nowdate);
 
	for($i=$nowyear; $i>=$firstyear; $i--){
		if($i == $firstyear && $i != $nowyear){
			for($j=12; $j>=$firstmonth; $j--){
				$monthtime = strtotime($i.'-'.$j);
				$years[$i][$j] = $monthtime;
			}
		}
		else if($i > $firstyear && $i < $nowyear){
			for($j=12; $j>=1; $j--){
				$monthtime = strtotime($i.'-'.$j);
				$years[$i][$j] = $monthtime;
			}
		}
		else if($i == $nowyear){
			$monthsub = 1;
			if($nowyear == $firstyear){
				$monthsub = $firstmonth;
			}
			for($j=$nowmonth; $j>=$monthsub; $j--){
				$monthtime = strtotime($i.'-'.$j);
				$years[$i][$j] = $monthtime;
			}
		}
	}	
	$default=idate('m',$default);
	$html='';
	if($default>0){
		$html.='<dt class="date-text">'.$default.'月</dt>';
	}else{
			$html='<dt class="date-text">全部</dt>';
	}
	$html.='<dd>';
	
	foreach ($years as $k=>$v) {
		$html.='<div class="optgp"><em class="gptitle">'.$k.'年</em>';
		foreach ($v as $sk=>$sv) {
			$param['time']=$sv;
			$url=hurl($m,$c,$a,$param);
			$html.='<a class="ms" href="'.$url.'" target="_self">'.$sk.'月</a>';
		}
		$html.='</div>';
	}
	$aurl=hurl($m,$c,$a,$param);
	if($isall)
		$html.='<a class="ms" href="'.$aurl.'">全部</a>';
	$html.='</dd><script type="text/javascript">HR.biz.hdatePickup("'.$parentid.'");</script>';
	return $html;
}
/**
 * 截取字符串
 * @param string $str
 * @param int $str_length
 * @param string $dot
 * @return string
 */
function hcut($str,$str_length=0,$dot=""){
	$str=strip_tags($str);
	$str=trim($str);
	$str=preg_replace('/\s(?=\s)/', '', $str);
	$str=preg_replace('/[\n\r\t]/', '', $str);
	$str=str_replace(array('&nbsp;', '&amp;', '&quot;', '&#039;', '&ldquo;', '&rdquo;', '&mdash;', '&lt;', '&gt;', '&middot;', '&hellip;'), array('', '', '', '', "", '', '', '', '', '', '', ''), $str);
	$str_oldlength=mb_strlen($str,"utf-8");
	if($str_length>0)
		$str=mb_substr($str,0,$str_length, 'utf-8');
	if($str_oldlength>$str_length){
		return $str.$dot;
	}else{	
		return $str;
	}
}
/**
 * 去除HTML字符
 * @param string $str
 * @param bool $isbr
 * @param bool $iskg
 * @return mixed
 */
function hreplacehtml($str,$isbr=false,$iskg=false)
{
	$html=array('&nbsp;', '&amp;', '&quot;', '&#039;', '&ldquo;', '&rdquo;', '&mdash;', '&lt;', '&gt;', '&middot;', '&hellip;');
	if($isbr){
		$html[]="\n";
		$html[]="\t";
		$html[]="\0";
		$html[]="\r";
		$html[]="<br />";
	}
	if($iskg){
		$html[]=" ";
	}
	foreach ($html as $h){
		$str=str_replace($h, '', $str);
	}
	return $str;
}
/**
 * 跳转
 * @param string $url
 */
function hheaderLocation($url) {
	@header('location: '.$url);
	exit;
}

/**
 * 处理城市信息
 * @param unknown_type $province
 * @param unknown_type $cityname
 * @return mixed|string
 */
function hcity($province,$cityname){
	$key=array("省","市","自治区","壮族","特别行政区","藏族","回族","维吾尔","自治州");
	foreach ($key as $k)
	{
		$cityname=str_replace($k, "", $cityname);
		$province=str_replace($k, "", $province);
	}
	if($cityname==$province){
		return $province;
	}else{
		return $province.$cityname;
	}
}

/**
 * 时间转换成星期
 * @param unknown_type $timestamp
 */
function hweekday($timestamp,$formatstr="星期"){
	$arr = array('日', '一', '二', '三', '四', '五', '六');
	$weeknum = date("w", $timestamp);
	$week= $arr[$weeknum];
	if($week){
		$week=$formatstr.$week;
	}
	return $week;
}

/**
 * 时间转换成中文月份
 * @param unknown_type $timestamp
 * @return string
 */
function hmonth($timestamp){
	$arr = array(' ','一', '二', '三', '四', '五', '六', '七', '八', '九', '十', '十一', '十二');
	$mouthnum = date("n", $timestamp);
	$mouth= $arr[$mouthnum];
	return $mouth;
}

/**
 * 文件大小换算
 * @param unknown_type $size 字节
 */
function hfilesizeconversion($size){
	if($size>1024*1024*1024*1024){
		return round($size/1024/1024/1024/1024,2).'TB';
	}elseif($size>1024*1024*1024){
		return round($size/1024/1024/1024,2).'GB';
	}elseif($size>1024*1024){
		return round($size/1024/1024,2).'MB';
	}elseif($size>1024){
		return round($size/1024,2).'KB';
	}else 
		return $size.'B';
}


/**
 * 根据时间查询周一
 * @param unknown_type $timestamp 某个星期的某一个时间戳，默认为当前时间
 * @param unknown_type $is_return_timestamp 是否返回时间戳，否则返回时间格式
 * @return Ambigous <>
 */
function hmonday($timestamp=0,$is_return_timestamp=true){
	static $cache ;
	$id = $timestamp.$is_return_timestamp;
	if(!isset($cache[$id])){
		if(!$timestamp) $timestamp = time();
		$monday_date = date('Y-m-d', $timestamp-86400*date('w',$timestamp)+(date('w',$timestamp)>0?86400:-/*6*86400*/518400));
		if($is_return_timestamp){
			$cache[$id] = strtotime($monday_date);
		}else{
			$cache[$id] = $monday_date;
		}
	}
	return $cache[$id];

}

/**
 * 根据时间查询周日
 * @param unknown_type $timestamp 某个星期的某一个时间戳，默认为当前时间
 * @param unknown_type $is_return_timestamp 是否返回时间戳，否则返回时间格式
 * @return Ambigous <>
 */
function hsunday($timestamp=0,$is_return_timestamp=true){
	static $cache ;
	$id = $timestamp.$is_return_timestamp;
	if(!isset($cache[$id])){
		if(!$timestamp) $timestamp = time();
		$sunday = hmonday($timestamp) + /*6*86400*/518400;
		if($is_return_timestamp){
			$cache[$id] = $sunday;
		}else{
			$cache[$id] = date('Y-m-d',$sunday);
		}
	}
	return $cache[$id];
}
/**
 * 生成Seo信息
 * @param string $title
 * @param string $description
 * @param array|string $keywords
 */
function hseo($title,$description='',$keywords=""){	
	$seo="<title>".htmlspecialchars($title)."</title>";
	$seo.='<meta name="description" content="'.htmlspecialchars($description).'" />';
	$key="";
	if(is_array($keywords)){
		$key=join($keywords, ',');
	}else{
		$key=$keywords;
	}
	$seo.='<meta name="keywords" content="'.htmlspecialchars($key).'" />';
	return $seo;
}
/**
 * 截字方法  1个英文字符算半个汉字
 * @param string $string
 * @param int $length 截取长度，按中文字数来算，2个英文算一个汉字 
 * @return string
 */
function hcut_utf8($string,$length,$dot='')
{
	$string=fx_utl::strip_script_replace($string);
	$string=strip_tags($string);
	$string=trim($string);
	$string=hreplacehtml($string,true,true);
	$chars = $string;
	$i=0;
	do{
		if (preg_match ("/[0-9a-zA-Z]/", $chars[$i])){//纯英文
			$m++;
		}
		else {
			$n++;
		}//非英文字节,
		$k = $n/3+$m/2;
		$l = $n/3+$m;//最终截取长度；$l = $n/3+$m*2？
		$i++;
	}while($k < $length);
	$str1 = mb_substr($string,0,$l,'utf-8');//保证不会出现乱码
	if($str1!=$string){
		return $str1.$dot;
	}else{
		return $str1;
	}
}
/**
 * 格式化数字，当超过 $max时，以$max+显示
 * @param int $num
 * @param int $max 默认为 99
 */
function hnum($num,$max=99){
	if($num>$max){
		$num=$max.'+';
	}
	return $num;
}



/**
 * 生成通用迷你第三方共享代码
 * 调用样例：客户端模板php部分 $thirdshare = thirdshareurl($url,$smtitle,$content,$subject);
 * 客户端JS调用输出：HR.biz.minishare('zwShare',[{'type':'sina','href':'{$thirdshare['sina']}'},{'type':'tt','href':'{$thirdshare['qqweibo']}'},{'type':'qq','href':'{$thirdshare['qqzone']}'}]);
 * @param string $url  hurl('rz','zw',show,array('id'=>1);
 * @param string $smtitle 三茅征文
 * @param string $content 征文详细内容描述
 * @param string $subject 征文标题
 * @return arry('sina'=>url,'qqweibo'=>url,'qqzone'=>url);
 */
function thirdshareurl($url,$smtitle,$content,$subject){
	$shareurl=urlencode($url);
	$text=hreplacehtml(strip_tags($content),true,true);
	$text=mb_substr($text,0,60,'utf-8');	
	$subject=hreplacehtml(strip_tags($subject),true,true);
	if(!$subject){
		$subject=mb_substr($text,0,20,'utf-8');	
	}	
	$shareinfo_sina='【'.$subject.'】- '."$smtitle：".$text.'... '.$shareurl.' (分享自@三茅人力资源网)';
	$shareinfo_sina=urlencode($shareinfo_sina);
	$shareinfo_qqweibo='【'.$subject.'】- '."$smtitle：".$text.'...(分享自@hrloo_com)';
	$shareinfo_qqweibo=urlencode($shareinfo_qqweibo);

	$shareinfo_qqzone1='【'.$subject.'】- '."$smtitle";
	$shareinfo_qqzone1=urlencode($shareinfo_qqzone1);

	$shareinfo_qqzone2="$smtitle"."：".$text."...";
	$shareinfo_qqzone2=urlencode($shareinfo_qqzone2);

	return array(
			'sina'=>"http://www.jiathis.com/send/?webid=tsina&uid=1541047&title=".$shareinfo_sina,
			'qqweibo'=>"http://www.jiathis.com/send/?webid=tqq&uid=1541047&url={$shareurl}&title=".$shareinfo_qqweibo,
			'qqzone'=>"http://www.jiathis.com/send/?webid=qzone&uid=1541047&url={$shareurl}&title={$shareinfo_qqzone1}&summary={$shareinfo_qqzone2}"
			);
}
function hnl2br($subject,$repeatbr=true){
	$subject=nl2br($subject);
	$subject=preg_replace("/(\<br \/\>\s*)+/","<br />", $subject);
	return $subject;
}

function htimediff($begin_time,$end_time)
{  
     $starttime = strtotime(date('Y-m-d',$begin_time));
     $endtime =  strtotime(date('Y-m-d',$end_time));;
     
     $timediff = $endtime-$starttime;
     $days = intval($timediff/86400);

     $timediff = $end_time-$begin_time;
     $remain = $timediff%86400;
     $hours = intval($remain/3600);
     $remain = $remain%3600;
     $mins = intval($remain/60);
     $secs = $remain%60;
     
     $res = array("days" => $days,"hour" => $hours,"min" => $mins,"sec" => $secs);
     return $res;
}

function hcut_html($html, $length){
	$html = str_replace('</p>', '***|***', $html);
	$html = str_replace('&nbsp;', '***-***', $html);
	$html = hcut_utf8($html, $length,'...');
	$html = str_replace('***|***', '<br/>', $html);
	$html = str_replace('***-***', '&nbsp;', $html);
	return $html;
}